package com.orphan.marketBack.controller;


import com.orphan.marketBack.po.dto.UsersManage;
import com.orphan.marketBack.service.IMallUserdetail2Service;
import com.orphan.marketBack.vo.UserVo;
import com.orphan.util.dto.GoodsDto;
import com.orphan.util.dto.UsersAuditDto;
import com.orphan.util.dto.UsersFreezeDto;
import com.orphan.util.dto.UsersManageDto;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wanghaiyu
 * @since 2021-07-13
 */
@RestController
@RequestMapping("/mall-user")
public class MallUserdetail2Controller implements Serializable {

  UsersManageDto manageDto=new UsersManageDto();
  @Autowired
  IMallUserdetail2Service service;

  @Autowired
  RabbitTemplate rabbitTemplate;

  @RequestMapping("UserAll")
  public List<UsersManage> UserAll() {
    List<UsersManage> usersManageDtos = service.userAll();

    return usersManageDtos;
  }
  @PostMapping("updateUser")
  public boolean updateUser(UsersManage user){
    boolean flag = false;
    if (user.getIsFrozen().equalsIgnoreCase("0")){
      flag = service.updateUser(user);
    }

    if (!flag){
      UsersManageDto manageDto=new UsersManageDto();
      BeanUtils.copyProperties(user,manageDto);
      rabbitTemplate.convertAndSend("queueUsers","queueUsers",manageDto);
    }
    return flag;
  }
  @PostMapping("selectUser")
  public List<UserVo> selectOne(UserVo user){
    List<UserVo> usersManageDtos = service.selectUser(user);
    return usersManageDtos;
  }
  //queues是队列Key的名字
//  @RabbitListener(queues = "queueGoosUpShow")
//  public void getMessage(GoodsDto pod){
//    System.out.println(pod);
//  }

//  @RabbitListener(queues = "userFreeze")
//  public void getMessage(UsersFreezeDto pod){
//    BeanUtils.copyProperties(pod,manageDto);
//    userFreeze(manageDto);
//  }
//public void userFreeze(UsersManageDto manageDto){
//    UsersManage usersManage=new UsersManage();
//    BeanUtils.copyProperties(manageDto,usersManage);
//  service.updateUser(usersManage);
//}
}
